import Designer from "../../studio/design/Designer"
import VJsonContext from "../../runtime/VJsonContext"
import {getDesignCmp} from "../../runtime/CmpStore"
import {renderIcon} from "./webutils";

export default {
    props: {
        designer: Designer,
        vcxt: VJsonContext,
    },
    methods: {
        renderIcon: renderIcon,
        getDesignCmp,
        onDragEnd(evt: any) {
            this.designer.dragEnd()
        },

        onDragAdd(parentList: any[], parentComponent: any, evt: any) {
            const newIndex = evt.newIndex
            if (!!parentList[newIndex]) {
                this.designer.setSelected(parentList[newIndex], {
                    parentComponent: parentComponent,
                    parentList: parentList,
                    indexOfParentList: newIndex,
                })
            }

            this.designer.emitHistoryChange()
        },

        onDragUpdate() {  /* 在VueDraggable内拖拽组件发生位置变化时会触发update，未发生组件位置变化不会触发！！ */
            this.designer.emitHistoryChange()
        },

        checkMove(evt) {
            return this.designer.checkWidgetMove(evt)
        },
    }
}